<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Brand</title>
</head>
<body>
<h2 align="center">${user.username}，欢迎您！</h2>
<hr>
<!--添加按钮-->
<p align="center"><input type="button" value="添加" id="add"></p>
<table border="1" cellspacing="0" width="80%" id="brandTable" align="center">
</table>
<hr>
<script src="../js/axios-0.18.0.js"></script><!--导入ajax的js文件:简化ajax书写-->
<script>
    /*给添加按钮绑定点击事件*/
    document.getElementById("add").onclick = function () {
        /*跳转到添加页面*/
        location.href = "addBrand.html";
    };
    //绑定页面加载完毕事件
    window.onload = function () {
        //发送ajax请求
        axios.get("http://localhost:8080/cookiesession_case/selectAllServletJson")
            .then((response) => {
                //处理响应数据
                //接收数据
                let brands = response.data;
                //定义表头
                let tableData = "<tr height='40px'>\n" +
                    "        <th>序号</th>\n" +
                    "        <th>品牌名称</th>\n" +
                    "        <th>企业名称</th>\n" +
                    "        <th>排序</th>\n" +
                    "        <th>品牌介绍</th>\n" +
                    "        <th>状态</th>\n" +
                    "        <th>操作</th>\n" +
                    "    </tr>";
                //定义单元格
                console.log(brands);
                for (let i = 0; i < brands.length; i++) {
                    let brand = brands[i];
                    let status = '启用';
                    if (brand.status == 0) {
                        status = '禁用';
                    }
                    tableData += "<tr align='center' height='50px'>\n" +
                        "        <td>" + (i + 1) + "</td>\n" +
                        "        <td>" + brand.brandName + "</td>\n" +
                        "        <td>" + brand.companyName + "</td>\n" +
                        "        <td>" + brand.ordered + "</td>\n" +
                        "        <td>" + brand.description + "</td>\n" +
                        "        <td>" + status + "</td>\n" +
                        "\n" +
                        "        <td><a href='/cookiesession_case/html/update.html?id="+ brand.id +"'>修改</a>" +
                        "           <a href='/cookiesession_case/deleteServletJson?id="+ brand.id +"'>删除</a></td>\n" +
                        "    </tr>";
                }
                //填充表格
                document.getElementById("brandTable").innerHTML = tableData;
            })
    };
</script>
</body>
</html>